﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using GodHelper.Models;

namespace GodHelper.Util
{
    /// <summary>
    /// 用户数据对象管理
    /// </summary>
    public class UserModelManager
    {
        private Hashtable UserMap = Hashtable.Synchronized(new Hashtable());
        private static UserModelManager UserModelManagerInstance = null;

        public static UserModelManager instance
        {
            get
            {
                if (UserModelManagerInstance == null)
                {
                    UserModelManagerInstance = new UserModelManager();
                }
                return UserModelManagerInstance;
            }
        }

        /// <summary>
        /// 添加用户数据model对象
        /// </summary>
        /// <param name="key"></param>
        /// <param name="um"></param>
        public void add(string key ,UserModel um)
        {
            if (this.UserMap.ContainsKey(key))
            {
                this.remove(key);
                //this.add(key, um);
            }
            this.UserMap.Add(key, um);
        }

        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public UserModel get(string key)
        {
            UserModel um = new UserModel();
            if (ContainKey(key))
            {
                um = (UserModel)this.UserMap[key];
            }
            return um;
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="key"></param>
        public void remove(string key)
        {
            if (this.UserMap.ContainsKey(key))
            {
                this.UserMap.Remove(key);
            }
        }

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool ContainKey(string key)
        {
            return this.UserMap.Contains(key);
        }


    }
}